<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="monitoring/layout">

<head>
    <title th:text="#{cas.dashboard.pagetitle}"></title>
</head>

<body id="cas">
    <div layout:fragment="content">

        <div class="viewDashboard">

            <div class="app-launcher">
                <h2 th:inline="text"><i class="fa fa-dashboard"></i>[[#{cas.dashboard.section.dashboard.title}]]</h2>
                <ul>
                    <li><a th:href="@{/status}">Status</a></li>
                                        
                    <li th:if="${actuatorEndpointsEnabled}">
                        <a th:href="@{/status/autoconfig}" class="casTooltip">
                            Auto Configuration
                            <span class="tooltiptext" th:text="#{cas.dashboard.tooltip.autoconfiguration}"></span>
                        </a>
                    </li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/beans}">Beans</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/mappings}">Endpoint Mappings</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/configprops}">Configuration Properties</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/dump}">Thread Dump</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/env}">Environment</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/health}">Health</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/info}">Info</a></li>
                    <li th:if="${actuatorEndpointsEnabled}"><a th:href="@{/status/metrics}">Metrics</a></li>
                    <li><a th:href="@{/status/stats}">Statistics Panel</a></li>
                    <li><a th:href="@{/status/config}">Config Panel</a></li>
                    <li><a th:href="@{/status/ssosessions}">SSO Sessions</a></li>
                    <li><a th:href="@{/status/logging}">Logging</a></li>
                    <li th:if="${trustedDevicesEnabled}"><a th:href="@{/status/trustedDevs}">Trusted Devices</a></li>
                    <li th:if="${authenticationEventsRepositoryEnabled}"><a th:href="@{/status/authnEvents}">AuthN Events</a></li>
                </ul>
            </div>
            <div class="app-launcher server-config">
                <h2 th:inline="text"><i class="fa fa-cogs"></i>[[#{cas.dashboard.section.configuration.title}]]</h2>
                <ul class="configserver">
                    <li th:if="${isDefaultProfile}"><a th:href="@{/configserver/cas/default}">Default Profile</a></li>
                    <li th:if="${isNativeProfile}"><a th:href="@{/configserver/cas/native}">Native Profile</a></li>
                </ul>
            </div>

            <div class="server-functions">
                <h2 th:inline="text"><i class="fa fa-server"></i>[[#{cas.dashboard.section.server.functions.title}]]</h2>
                <ul>
                    <li th:if="${restartEndpointEnabled}">
                        <form method="post" th:action="@{/status/restart}">
                            <button class="btn btn-restart"
                                type="button"
                                data-toggle="modal"
                                data-target="#myModal"
                                th:inline="text"
                                th:attr="data-title=#{cas.dashboard.action.button.reboot.modal.title},data-message=#{cas.dashboard.action.button.reboot.modal.message}"
                            >
                                <i class="fa fa-undo"></i>[[#{cas.dashboard.action.button.reboot}]]
                            </button>
                        </form>
                    </li>
                    <li>
                        <form th:method="${refreshMethod}" th:action="${refreshEndpoint}">
                            <button class="btn btn-refresh"
                                type="button"
                                data-toggle="modal"
                                data-target="#myModal"
                                th:inline="text"
                                    th:attr="data-title=#{cas.dashboard.action.button.refresh.modal.title},data-message=#{cas.dashboard.action.button.refresh.modal.message}"
                            >
                                <i class="fa fa-refresh"></i>[[#{cas.dashboard.action.button.refresh}]]
                            </button>
                        </form>
                    </li>
                    <li th:if="${shutdownEndpointEnabled}">
                        <form method="post" th:action="/status/shutdown">
                            <button type="button" class="btn btn-shutdown"
                                data-toggle="modal"
                                data-target="#myModal"
                                th:inline="text"
                                th:attr="data-title=#{cas.dashboard.action.button.shutdown.modal.title},data-message=#{cas.dashboard.action.button.shutdown.modal.message}"
                            >
                                <i class="fa fa-power-off"></i>
                                [[#{cas.dashboard.action.button.shutdown}]]
                            </button>
                        </form>
                    </li>
                </ul>
            </div>

            <div layout:include="fragments/modal :: modal(modalId='myModal', modalHeader='Message', modalButtons='true')" th:remove="tag">
                <p layout:fragment="modal-content">Message goes here!</p>
            </div>

            <script>
                $('#myModal').on('show.bs.modal', function (event) {
                    var button = $(event.relatedTarget);
                    var modal = $(this);

                    modal.find('.modal-title').text( button.data('title') );
                    modal.find('.modal-body').text( button.data('message') );

                    var form = $(event.relatedTarget).closest('form');

                    modal.find('.modal-footer button.btn-primary').data('form', form);
                })

                $('#myModal').find('.modal-footer button.btn-primary').on('click', function(){
                    $(this).data('form').submit();
                });

            </script>
        </div>

    </div>
</body>
</html>
